#include "sysConfig.h"

int N_NETWORK;
int N_PLATE;
int N_PAIR;
int N_TEMPLATE;

int PlateConf[MAX_PLATE_TOTAL][3];
int TemplateConf[MAX_PLATE_TOTAL][MAX_TEMPLATE];
int PairConf[MAX_PAIR_TOTAL][2];

#define myConf_NPLATE 8
#define myConf_N_NETWORK 2
#define myConf_NPAIR 4
#define myConf_TEMPLATE 2


const int myPlateConf[myConf_NPLATE][3] =
    {{0,1,1},{0,1,2},{0,2,1},{0,2,2},{1,1,1},{1,1,2},{1,2,1},{1,2,2}};
    

const int myPairConf[myConf_NPAIR][2] = 
    {{0,4},{1,5},{2,6},{3,7}};


const int myTemplateConf[myConf_NPLATE][myConf_TEMPLATE] = 
    {{90,30},{30,90},{90,30},{30,90},{90,30},{30,90},{90,30},{30,90}};

int getAbs (T_plateList PL, int id){
    return PL.plate[id].absis;
}
int getOrd (T_plateList PL, int id){
    return PL.plate[id].ordinat;
}

int getNPlateinNetw (T_plateMap PM, int netID){
    return PM.netw[netID].nPlate;
}

int getIDnInNetw(T_plateMap PM, int netID, int idx){
    return PM.netw[netID].IDList[idx];
}

int getPairID(T_pairList PL, int id){
    return PL.pair[id];
}

int getTemplateID(T_templateList TL, int id, int tempID){
    return TL.dt[id].temp[tempID];
}

void initDataSet(){
    int i,j;
    
    N_PLATE = myConf_NPLATE;
    N_NETWORK = myConf_N_NETWORK;
    N_PAIR = myConf_NPAIR;
    N_TEMPLATE = myConf_TEMPLATE;
    
    for (i = 0; i < N_PLATE; ++i){
        for (j = 0; j < 3; ++j){
            PlateConf[i][j] = myPlateConf[i][j];
        }
    }
    
    for (i = 0; i < N_PAIR; ++i){
        for (j = 0; j < 2; ++j){
            PairConf[i][j] = myPairConf[i][j];
        }
    }
    
    for (i = 0; i < N_PLATE; ++i){
        for (j = 0; j < N_TEMPLATE; ++j){
            TemplateConf[i][j] = myTemplateConf[i][j];
        }
    }
}

void initPlateDB( T_plateDB *PDB){
    int i;
    T_plateData temp;
    temp.condition = 1;
    temp.targetTemp = 0;
    temp.BGTemp = 0;
    temp.ActTemp = 0;
    
    for (i = 0; i < MAX_PLATE_TOTAL; ++i){
        setPlateData(PDB, i, temp);        
    }
}

int isPlateDataEqual(T_plateData PD1, T_plateData PD2){
    return ((PD1.condition == PD2.condition)&&
            (PD1.targetTemp == PD2.targetTemp)&&
            (PD1.BGTemp == PD2.BGTemp)&&
            (PD1.ActTemp == PD2.ActTemp)
            );
}

T_plateData getPlateData(T_plateDB PDB, int id){
    return PDB.dat[id];
}

void setPlateData(T_plateDB *PDB, int id, T_plateData PD){
    (*PDB).dat[id] = PD;
}
		

void initPlateList(	T_plateList *PL ) {
	int i;
	
	// //Init PlateList
	for (i=0; i<N_PLATE; ++i){
		(*PL).plate[i].ordinat = PlateConf[i][2];	
		(*PL).plate[i].absis = PlateConf[i][1];	
		}
}	



void initPlateMap( T_plateMap *PM ){
	int i,k;
	int _nPlate;
	
	//Init PlateMap
	k=0;
	_nPlate = 1;

	for (i=0; i<N_PLATE; ++i){
		while (k < PlateConf[i][0]){
			k++;
			_nPlate = 1;
		} 		
		(*PM).netw[k].IDList[_nPlate-1] = i;
		(*PM).netw[k].nPlate = _nPlate;
		_nPlate++;		
	}
}

void initPairList( T_pairList *PP ){
	int i;
	
	//Init PairList
	for (i=0; i<N_PAIR; ++i){
		(*PP).pair[PairConf[i][0]]=PairConf[i][1];
		(*PP).pair[PairConf[i][1]]=PairConf[i][0];
	}
}

void initTemplateList(T_templateList *TL){
	int i,j;

	// //Init TemplateList
	for (i=0; i<N_PLATE; ++i){
		for(j=0; j<N_TEMPLATE; ++j){
		(*TL).dt[i].temp[j]=TemplateConf[i][j];
		}
	}	
}


#ifdef PC
void printPlateList( T_plateList PlateList ){
	int i;
	for (i=0; i<N_PLATE; ++i){
		printf("%d -- (%d,%d)\n",i,PlateList.plate[i].absis,PlateList.plate[i].ordinat);
	}
	printf("\n"); printf("\n");
}

void printPlateMap(T_plateMap PlateMap){
	int i,j;
	for (i=0; i<N_NETWORK; ++i){
		printf("\n-- Netw. %d  --> %d\n",i, PlateMap.netw[i].nPlate);
		for (j=0; j<PlateMap.netw[i].nPlate; ++j){
			printf(" %d",PlateMap.netw[i].IDList[j]);
		}
	}
	printf("\n"); printf("\n");
}


void printPairList(T_pairList PairList){
	int i;
	for (i=0; i<N_PLATE; ++i){
		printf("Pair: %d -- %d\n",i,PairList.pair[i]);
	}
	printf("\n"); printf("\n");
}

void printTemplateList(T_templateList TemplateList){
	int i,j;
	for (i=0; i<N_PLATE; ++i){
		printf("\n -- plate: %d\ntemplate: ",i);
		for(j=0; j<N_TEMPLATE; ++j){
			printf(" %d",TemplateList.dt[i].temp[j]);
		}
	}	
	printf("\n"); printf("\n");
}

#endif

